<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/31
 * Time: 11:47
 */

namespace App\Http\Controllers\Api\V1;


use App\Models\ClassConfig;
use App\Models\Coach;
use App\Models\School;
use App\Models\Student;
use App\Models\StudentCoach;
use App\Models\StudentCount;
use App\Models\User;
use App\Models\TcpStudytime;
use App\Repositories\CoachsRepository;
use App\Repositories\EvaluationRepository;
use App\Repositories\StudentRepository;
use App\Repositories\MessageRepository;
use App\Repositories\StudytimeRepository;
use App\Repositories\SubscribesRepository;
use App\Repositories\StudentCountRepository;
use App\Repositories\CommentsRepository;
use App\Repositories\StudentStateRepository;
use App\Repositories\OrderListRepository;
use App\Transformers\CoachDetailsTransformer;
use App\Transformers\EvaluationTransformer;
use App\Transformers\FeedbackTransformer;
use App\Transformers\MessageTransformer;
use App\Transformers\OperationTransformer;
use App\Transformers\PeriodCoachTransformer;
use App\Transformers\PeriodTransformer;
use App\Transformers\SubscribeTransformer;
use App\Transformers\MySubscribeTransformer;
use App\Transformers\PaymentDetailTransformer;
use App\Models\SchoolConfig;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Libs\Umeng;

class StudentController extends BaseController
{
    protected $study;
    protected $coachs;
    protected $evaluation;
    protected $subscribe;
    protected $student;
    protected $message;
    protected $comments;
    protected $student_count;
    protected $student_state;
    protected $order_list;

    public function __construct(
        StudytimeRepository $studytimeRepository,
        CoachsRepository $coachsRepository,
        EvaluationRepository $evaluationRepository,
        SubscribesRepository $subscribesRepository,
        StudentRepository $studentRepository,
        MessageRepository $messageRepository,
        CommentsRepository $comments,
        StudentCountRepository $studentCount,
        StudentStateRepository $studentState,
        OrderListRepository $order_list
    )
    {
        $this->student = $studentRepository;
        $this->study = $studytimeRepository;
        $this->coachs = $coachsRepository;
        $this->evaluation = $evaluationRepository;
        $this->subscribe = $subscribesRepository;
        $this->message = $messageRepository;
        $this->comments = $comments;
        $this->student_count = $studentCount;
        $this->student_state = $studentState;
        $this->order_list = $order_list;
    }

    /**
     * @api {get} /student 学员首页(student index)
     * @apiDescription 学员首页(student index)
     * @apiGroup Student
     * @apiSampleRequest /api/student
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": {
     *              "banner": [
     *                  {
     *                      'id' => 1,
     *                      'imgurl' => 'url_path',
     *                  }
     *               ],
     *               "latest_train": {
     *              "starttime": "2017-05-24 09:27:45",
     *              "endtime": "2017-05-24 09:35:39",
     *              "km": 2,
     *              "created_at": "2017-05-24 09:35:41",
     *              "valid_putime": 0,
     *              "novalid_putime": 0
     *              }
     *          }
     *   }
     */
    public function index(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->student->getStudentInfo($user->item_id);//学员信息

        return $this->successResponse('success',['data'=>$data]);
    }

    /**
     * @api {get} /student/studyCar 预约学车(student studycar)
     * @apiDescription 预约学车(student studycar)
     * @apiGroup Student
     * @apiSampleRequest /api/student/studyCar
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *        "message": "success",
    "code": 200,
    "data": {
    "schoolConfig": {
    "id": 93,
    "school_id": 36,
    "issubscribe": 1,
    "istheory": 0,
    "sch_putime_length": 0,
    "sch_putime_interval": 0,
    "sch_putime_operation": 0,
    "sch_vip1_univalence": "0.00",
    "sch_vip2_univalence": "0.00",
    "sch_vip3_univalence": "0.00",
    "sch_vip4_univalence": "0.00",
    "sch_vip5_univalence": "0.00",
    "sch_sign": 0,
    "sch_signtime": 0,
    "putime_template": 1,
    "orderputime": 0,
    "quxiaoputime": 0,
    "isshow_coachofstudentnum": 1,
    "isshow_allputime": 0,
    "isshow_allcoachputime": 0,
    "slogan": "",
    "putime_day": 3,
    "recommend": 0,
    "column": 1,
    "ischeck": 2,
    "student_login": 2,
    "video_player_num": 0,
    "self_motion_comment": 0,
    "self_motion_comment_day": 0,
    "unlimited_putime_max": 99,
    "created_at": "2017-04-17 11:55:32",
    "updated_at": "2017-04-17 11:57:02",
    "open_recruit": 1
    }
    }
     *   }
     */
    public function studyCar(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }
//        $param = [
//            'day'=>$request->get('day'),
//            'km'=>$request->get('km'),
//            'student_id'=>$user->item_id,
//            'page'=>$request->get('page',1),
//            'size'=>$request->get('size',10),
//            'name'=>$request->get('name')
//        ];

//        $lists = $this->study->index($param);
//
//        if(!empty($lists)){
//            $transformer = new PeriodCoachTransformer;
//
//            foreach($lists as $k => $coach){
//                $lists[$k] = $transformer->transform($coach);
//            }
//        }

        $data['schoolConfig'] = SchoolConfig::where('school_id',  $user->item->school->id)->first();
//        $data['list'] = $lists;


        return $this->successResponse('success',['data'=>$data]);
    }


    /**
     * @api {get} /student/periodList 预约学车信息(student studycar)
     * @apiDescription 预约学车信息
     * @apiGroup Student
     * @apiSampleRequest /api/student/periodList
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {String} [date]  date
     * @apiParam {String} [km]  km
     * @apiParam {String} [startime]  startime
     * @apiParam {String} [endtime]  endtime
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *        "message": "success",
                "code": 200,
                "data": {
                "schoolConfig": {
                "id": 93,
                "school_id": 36,
                "issubscribe": 1,
                "istheory": 0,
                "sch_putime_length": 0,
                "sch_putime_interval": 0,
                "sch_putime_operation": 0,
                "sch_vip1_univalence": "0.00",
                "sch_vip2_univalence": "0.00",
                "sch_vip3_univalence": "0.00",
                "sch_vip4_univalence": "0.00",
                "sch_vip5_univalence": "0.00",
                "sch_sign": 0,
                "sch_signtime": 0,
                "putime_template": 1,
                "orderputime": 0,
                "quxiaoputime": 0,
                "isshow_coachofstudentnum": 1,
                "isshow_allputime": 0,
                "isshow_allcoachputime": 0,
                "slogan": "",
                "putime_day": 3,
                "recommend": 0,
                "column": 1,
                "ischeck": 2,
                "student_login": 2,
                "video_player_num": 0,
                "self_motion_comment": 0,
                "self_motion_comment_day": 0,
                "unlimited_putime_max": 99,
                "created_at": "2017-04-17 11:55:32",
                "updated_at": "2017-04-17 11:57:02",
                "open_recruit": 1
                }
                }
     *   }
     */
    public function periodList(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'date'=>$request->get('date'),
            'km'=>$request->get('km'),
            'startime'=> strtotime($request->get('startime')),
            'endtime'=> strtotime($request->get('endtime')),
            'student_id' => $user->item_id,
        ];

        $lists = $this->study->index($param);


        if(!empty($lists)){

            foreach($lists as $k => $coach){
               $lists[$k]['userid'] = $coach['coach_id'];
               $lists[$k]['schoolname'] = '';
            }
        }

        $data['list'] = $lists;

        return $this->successResponse('success',['data'=>$lists]);
    }



    /**
     * @api {get} /student/coachDetails 教练详情(student coachDetails)
     * @apiDescription 教练详情(student coachDetails)
     * @apiGroup Student
     * @apiSampleRequest /api/student/coachDetails
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [coach_id]  教练id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *  {
     *      "message": "操作成功",
     *      "status_code": 200,
     *      "data": {
     *          "id": 1183,//教练id
     *          "school_id": 36,//驾校id
     *          "coachnum": "4151666593540518",//编号
     *          "name": "殷若兰",//姓名
     *          "photo": "http://img.exc360.com/photo/2016/12/19/1482130270_4Ky.jpg",//教练头像
     *          "sex": 2,//性别 性别 1:男  2：女
     *          "idcard": "511526198106104173",//身份证号
     *          "mobile": "13566656546",//电话
     *          "schoolname": "神通测试驾校",//所属驾校
     *          "address": "四川省宜宾市珙县",//教练联系地址
     *          "teachpermitted": "C1",//准教车型
     *          "evaluationrate": "100",//满意率
     *          "evaluateNum": 1,//评价总数
     *          "evaluate": [
     *              {
     *                  "id": 1,
     *                  "school_id": 36,//驾校id
     *                  "student_id": 12317,//学员id
     *                  "stunum": "7525361996760437",//学员编号
     *                  "putime_id": 0,//学时id
     *                  "evalobject": "4151666593540518",//评价对象编号
     *                  "type": 1,//评价对象类型 1：教练 2：培训机构
     *                  "overall": 3,//总体满意度  1:一星 2:二星 3:三星 4:四星 5:五星（最满意）
     *                  "part": 1,//培训部分 1:第一部分 \r\n2:第二部分 \r\n3:第三部分 \r\n4:第四部分
     *                  "evaluatetime": "2017-02-14 00:00:00",//评价时间
     *                  "srvmanner": "让人",//评价用语列表  英文逗号分隔
     *                  "teachlevel": "感叹",//个性化评价
     *                  "coachreply": null,//教练回复
     *                  "coachreplytime": null,//教练回复时间
     *                  "schoolreply": null,//驾校回复
     *                  "schoolreplytime": null,//驾校回复时间
     *                  "created_at": "2017-02-14 14:29:50",//
     *                  "updated_at": "2017-02-14 14:29:50",//
     *                  "stuname": "李新国",//学员姓名
     *                  "stuphoto": "http://img.exc360.com/photo/2017/03/30/1490855913_sPS.jpg"//学员头像
     *              }
     *          ],
     *          "putime": [
     *               {
     *                  "id": 20,
     *                  "school_id": 36,//驾校id
     *                  "coach_id": 1183,//教练id
     *                  "km": "2",//科目 2:科目二    3:科目三
     *                  "startime": 1494310200,//开始学车时间
     *                  "endtime": 1494313800,//结束时间
     *                  "minute": 60,//时长 分钟
     *                  "max": 1,//允许预约人数
     *                  "only": 1,//还差 N 人
     *                  "reserve": 0,//实际预约人数
     *                  "sum_period": 1,//总学时
     *                  "status": 0 //状态 0 待确认 1已确认  2已申诉
     *              }
     *          ]
     *      }
     *  }
     */
    public function coachDetails(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token
        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $coach_id = $request->get('coach_id');
        if(!$coach_id){
            return $this->errorResponse('参数错误');
        }
        $list = $this->coachs->getByInfo($user->item,$coach_id);

        $transformer = new CoachDetailsTransformer;

        $list = $transformer->transform($list);
        return $this->successResponse('success',['data' => $list]);
    }

    /**
     * @api {get} /student/comments 学员学时评论列表(student evaluate)
     * @apiDescription 学员学时评论列表(student evaluate)
     * @apiGroup Student
     * @apiSampleRequest /api/student/comments
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [page=1]  第N页
     * @apiParam {Number} [size=10]  每页N条
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "操作成功",
     *       "status_code": 200,
     *       "data": [
     *          {
     *              "id": 1,
     *              "stuname": "李新国",//学员姓名
     *              "stuphoto": "http://img.exc360.com/photo/2017/03/30/1490855913_sPS.jpg",//学员头像
     *              "overall": 3,//总体满意度  1:一星 2:二星 3:三星 4:四星 5:五星（最满意）
     *              "part": 1, //培训部分 1:第一部分 \r\n2:第二部分 \r\n3:第三部分 \r\n4:第四部分
     *              "evaluatetime": "2017-02-14 00:00:00",//评价时间
     *              "srvmanner": "让人",//评价用语列表  英文逗号分隔
     *              "teachlevel": "感叹",//个性化评价
     *              "coachreply": null,//教练回复
     *              "coachreplytime": null,//教练回复时间
     *              "schoolreply": null,//驾校回复
     *              "schoolreplytime": null//驾校回复时间
     *          }
     *       ],
     *       "meta": {
     *          "pagination": {
     *              "total": 1,
     *              "count": 1,
     *              "per_page": 15,
     *              "current_page": 1,
     *              "total_pages": 1,
     *              "links": []
     *          }
     *      }
     *   }
     */
    public function comments(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $size = $request->get('size',10);

        $param = [
            'page'=>$request->get('page', 1)
        ];

        $lists = $this->comments->index($param,$user->item,$size);


        return $this->successResponse('success',['data'=>$lists]);
    }

    /**
     * @api {get} /student/evaluateDetails 评论详情(student evaluateDetails)
     * @apiDescription 评论详情(student evaluateDetails)
     * @apiGroup Student
     * @apiSampleRequest /api/student/evaluateDetails
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [evaluate_id]  评论记录id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "操作成功",
     *       "status_code": 200,
     *       "data": {
     *           "id": 1,
     *           "stuname": "李新国",//学员姓名
     *           "stuphoto": "http://img.exc360.com/photo/2017/03/30/1490855913_sPS.jpg",//学员头像
     *           "overall": 3,//总体满意度  1:一星 2:二星 3:三星 4:四星 5:五星（最满意）
     *           "part": 1, //培训部分 1:第一部分 \r\n2:第二部分 \r\n3:第三部分 \r\n4:第四部分
     *           "evaluatetime": "2017-02-14 00:00:00",//评价时间
     *           "srvmanner": "让人",//评价用语列表  英文逗号分隔
     *           "teachlevel": "感叹",//个性化评价
     *           "coachreply": null,//教练回复
     *           "coachreplytime": null,//教练回复时间
     *           "schoolreply": null,//驾校回复
     *           "schoolreplytime": null//驾校回复时间
     *       }
     *   }
     */
    public function evaluateDetails(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $evaluate_id = $request->get('evaluate_id');
        if(!$evaluate_id){
            return $this->errorResponse('参数错误');
        }
        $list = $this->evaluation->getById($evaluate_id);
        return $this->responseItem($list,new EvaluationTransformer());
    }

    /**
     * @api {get} /student/evaluateStatistics 评论统计(student evaluateStatistics)
     * @apiDescription 评论统计(student evaluateStatistics)
     * @apiGroup Student
     * @apiSampleRequest /api/student/evaluateStatistics
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": {
     *              "count": 1, //总评论数
     *              "evaluationrate": "100",//满意率
     *              "satisfaction": 1,//好评数
     *              "general": 0,//一般即中评数
     *              "dissatisfaction": 0 //差评数
     *          }
     *   }
     */
    public function evaluateStatistics(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $list = $this->comments->statistics($user->item_id);

        return $this->successResponse('success',['data'=>$list]);
    }

    /**
     * @api {get} /student/coachStudytime 教练排班(student coachStudytime)
     * @apiDescription 教练排班(student evaluateStatistics)
     * @apiGroup Student
     * @apiSampleRequest /api/student/coachStudytime
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [coach_id]  教练id
     * @apiParam {String} [times] 日期 如：2017-05-31
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": [
     *               {
     *                  "id": 20,
     *                  "school_id": 36,//驾校id
     *                  "coach_id": 1183,//教练id
     *                  "km": "2",//科目 2:科目二    3:科目三
     *                  "startime": 1494310200,//开始学车时间
     *                  "endtime": 1494313800,//结束时间
     *                  "minute": 60,//时长 分钟
     *                  "max": 1,//允许预约人数
     *                  "only": 1,//还差 N 人
     *                  "reserve": 0,//实际预约人数
     *                  "sum_period": 1,//总学时
     *                  "status": 0 //状态 0 待确认 1已确认  2已申诉
     *                  "paymode":2 //模式 1：先学后付  2:先付后学
     *               },
     *               {
     *                  "id": 20,
     *                  "school_id": 36,//驾校id
     *                  "coach_id": 1183,//教练id
     *                  "km": "2",//科目 2:科目二    3:科目三
     *                  "startime": 1494310200,//开始学车时间
     *                  "endtime": 1494313800,//结束时间
     *                  "minute": 60,//时长 分钟
     *                  "max": 1,//允许预约人数
     *                  "only": 1,//还差 N 人
     *                  "reserve": 0,//实际预约人数
     *                  "sum_period": 0.01,//总金额
     *                  "status": 0 //状态 0 待确认 1已确认  2已申诉
     *                  "paymode":1 //模式 1：先学后付  2:先付后学
     *              }
     *          ]
     *   }
     */
    public function coachStudytime(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'coach_id'=>$request->get('coach_id'),
            'times'=>$request->get('times',date('Y-m-d')),
            'student_id'=>$user->item_id
        ];

        $lists = $this->study->crewScheduling($param);

        return $this->successResponse('success',['data'=>$lists]);
    }


    /**
     * @api {get} /student/coachPeriodtime 教练排班预览(student coachPeriodtime)
     * @apiDescription 教练排班(student evaluateStatistics)
     * @apiGroup Student
     * @apiSampleRequest /api/student/coachPeriodtime
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [coach_id]  教练id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": [
     *               {
     *                  "id": 20,
     *                  "school_id": 36,//驾校id
     *                  "coach_id": 1183,//教练id
     *                  "km": "2",//科目 2:科目二    3:科目三
     *                  "startime": 1494310200,//开始学车时间
     *                  "endtime": 1494313800,//结束时间
     *                  "minute": 60,//时长 分钟
     *                  "max": 1,//允许预约人数
     *                  "only": 1,//还差 N 人
     *                  "reserve": 0,//实际预约人数
     *                  "sum_period": 1,//总学时
     *                  "status": 0 //状态 0 待确认 1已确认  2已申诉
     *                  "paymode":2 //模式 1：先学后付  2:先付后学
     *               },
     *               {
     *                  "id": 20,
     *                  "school_id": 36,//驾校id
     *                  "coach_id": 1183,//教练id
     *                  "km": "2",//科目 2:科目二    3:科目三
     *                  "startime": 1494310200,//开始学车时间
     *                  "endtime": 1494313800,//结束时间
     *                  "minute": 60,//时长 分钟
     *                  "max": 1,//允许预约人数
     *                  "only": 1,//还差 N 人
     *                  "reserve": 0,//实际预约人数
     *                  "sum_period": 0.01,//总金额
     *                  "status": 0 //状态 0 待确认 1已确认  2已申诉
     *                  "paymode":1 //模式 1：先学后付  2:先付后学
     *              }
     *          ]
     *   }
     */
    public function coachPeriodtime(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'coach_id'=>$request->get('coach_id'),
        ];

        $lists = $this->study->periodScheduling($param);

        return $this->successResponse('success',['data'=>$lists]);
    }


    /**
     * @api {get} /student/subscribeHint 预约提示(student subscribeHint)
     * @apiDescription 预约提示(student subscribeHint)
     * @apiGroup Student
     * @apiSampleRequest /api/student/subscribeHint
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [pid]  预约时段id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": []
     *   }
     */
    public function subscribeHint(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $pid = $request->input('pid');

        $data = $this->study->getById($pid);

        $data->price = $this->subscribe->getPrice($user->item, $data);

        if($data->max==1){
            $data->study_time = $data->sum_period;
        }elseif ($data->max > 1){
            $data->study_time = $data->sum_period/$data->max;
        }

        $data->ssms = '';
        $student_count = StudentCount::where('student_id',$user->item_id)->first();
        if($user->item->service_id){
            $data->ssms = $user->item->service->paymode;

            $data->is_pickup = 0;
            $data->pickup_num = 0;

            $service_config = ClassConfig::where('school_id',$user->item->school_id)->where('service_id',$user->item->service_id)->first();

            if($service_config){
                $data->pickup_num = $student_count ? $student_count->pickupnum : 0;

                if($service_config->stu_putime_pickup > 0 && $data->pickup_num > 0){
                    $data->is_pickup = 1;
                }
            }
        }

        $data->time_left = 0;
        if($student_count){
            $km = 'km'.$data->km.'period';
            $data->time_left = $student_count->$km;
        }

        $transfomer = new PeriodTransformer;

        $data = $transfomer->transform($data);

        return $this->successResponse('success',['data'=>$data]);
    }

    /**
     * @api {post} /student/subscribe 预约处理(student subscribe)
     * @apiDescription 预约处理(student subscribe)
     * @apiGroup Student
     * @apiSampleRequest /api/student/subscribe
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [pid]  预约时段id
     * @apiParam {Number} [ispick_up]  是否接送
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "预约成功",
     *       "code": 200
     *   }
     */
    public function subscribe(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'putime_id'=>$request->get('pid'),
            'student_id'=>$user->item_id,
            'user_id'=>$user->id,
            'ispick_up'=>$request->get('ispick_up'),
        ];
        if(!$param['putime_id']){
            return $this->errorResponse('参数错误');
        }
        $status_info = $this->subscribe->store($param);
        if($status_info !== false){

            if($status_info->km == 2){
                $km = '科二实操练习';
            }else{
                $km = '科三实操练习';
            }
            $msg['content'] = '你预约了'.$status_info->coach->name.'教练：'.date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime).' 的'.$km.'，要按时到达哦';
            $msg['from_type'] = 3;//消息来源学员
            $msg['from_id'] = $user->item->id;
            $msg['to_type'] = 1;//消息接受学员
            $msg['to_id'] = $user->item->id;

            if($user->item->device_type == 'ios'){
                $msg['device_type'] = 1;
            }elseif($user->item->device_type == 'android'){
                $msg['device_type'] = 2;
            }
            $this->message->store($msg);

            if( $user->item->device_token ){
                $umen = new Umeng($user->item->device_type, 3);
                $umen->sendNotificationToDevices(['title' => '预约提示', 'text' => $msg['content'], 'device_tokens' => $user->item->device_token]);
            }
            //发送给教练
            $msg['content'] = $user->item->name.'学员预约了您：'.date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime).' 的'.$km;
            $msg['from_type'] = 1;//消息来源
            $msg['from_id'] = $user->item->school_id;
            $msg['to_type'] = 2;//消息接受教练
            $msg['to_id'] = $status_info->coach->id;
            $msg['device_type'] = 3;
            $this->message->store($msg);

            $coach_id = User::where('item_id',$status_info->coach->id)->where('item_type','App\Models\Coach')->value('id');
            $student_count = StudentCount::where('student_id',$user->item_id)->first();
            $data['km'] = $status_info->km;
            $data['status'] = 1;
            $data['userId'] = $user->id;
            $data['name']  = $user->item->name;
            $data['phone'] = $user->item->phone;
            $data['cocahUserId'] = $coach_id;
            $data['cocahName'] = $status_info->coach->name;
            $data['cocahPhone'] = $status_info->coach->mobile;
            $data['location'] = '';
            $data['use_hours'] = $status_info->study_time;
            $data['surplus_hours'] = $student_count->km2period + $student_count->km3period;
            $data['times'] = date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime);
            $data['userType'] = 1;
            $this->subscribe->post_weixin_student_yy($data);
            return $this->successResponse('预约成功');
        }else{
            return $this->errorResponse($this->subscribe->error?$this->subscribe->error:'预约失败');
        }


    }

    /**
     * @api {get} /student/mySubscribe 我的预约(student mySubscribe)
     * @apiDescription 我的预约(student mySubscribe)
     * @apiGroup Student
     * @apiSampleRequest /api/student/mySubscribe
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [status=1]  状态 1：未学习  2：未付款  3：已完成  4：已取消 5：已完成未待评价
     * @apiParam {Number} [page=1]  第N页
     * @apiParam {Number} [size=10]  每页N条
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *  {
     *      "message": "操作成功",
     *      "status_code": 200,
     *      "data": [
     *          {
     *              "id": 156, //学时id
     *              "school_id": 36, //驾校id
     *              "coach_id": 507,//教练id
     *              "coachname": "肖均2",//教练姓名
     *              "coachphoto": "http://img.exc360.com/photo/2016/10/23/1477189571_PS0.jpg",//教练头像
     *              "km": 2,//科目
     *              "startime": 1496383800,//学时开始时间
     *              "endtime": 1496387400,//学时结束时间
     *              "minute": 60,//时长
     *              "max": 1,//最大预约人数
     *              "only": 0,//剩余预约人数
     *              "reserve": 1,//已预约人数
     *              "sum_period": 1,//总学时
     *              "status": 0,//状态 0 待确认 1已确认  2已申诉
     *              "student_id": 12317, //学员id
     *              "is_pick_up": 0,//是否接送 1：接送
     *              "lat": 0,//经度
     *              "lng": 0,//纬度
     *              "address": "",//接送地址
     *              "paymodel": 2,//付费模式 1：先学后付  2：先付后学
     *              "money": 1, //应付费用
     *              "operation_time": "2017-06-02 13:56:06"//预约时间 或 取消时间
     *          }
     *      ],
     *      "meta": {
     *          "count": {//数据统计
     *              "notStudy": 1, //未完成
     *              "notPayment": 0,//未付款
     *              "accomplish": 0,//已完成
     *              "cancel": 1//已取消
     *          },
     *          "pagination": {
     *              "total": 1,
     *              "count": 1,
     *              "per_page": 10,
     *              "current_page": 1,
     *              "total_pages": 1,
     *              "links": []
     *          }
     *      }
     *  }
     */
    public function mySubscribe(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $service = '';
        if($user->item->service_id){
            $service = $user->item->service->paymode;
        }

        $param = [
            'student_id'=>$user->item_id,
            'paymode' => $service,
            'type'=>$request->get('status',1),
            'page'=>$request->get('page')
        ];
        $size = $request->get('size',10);

        $data = $this->subscribe->index($param,'',$size);

        $result = [];
        $trans = new MySubscribeTransformer;

        foreach($data['list'] as $list){

            $a[] = $trans->transform($list);
            $result['list'] = $a;
        }

        $result['count'] = $data['count'];

        return $this->successResponse('success',['data' =>$result]);

    }


    /**
     * @api {get} /student/mySubscribeCount 我的预约统计(student mySubscribe)
     * @apiDescription 我的预约统计(student mySubscribe)
     * @apiGroup Student
     * @apiSampleRequest /api/student/mySubscribeCount
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *  {
     *      "message": "操作成功",
     *      "status_code": 200,
     *      "data": [
     *          "count": {//数据统计
     *              "notStudy": 1, //未完成
     *              "notPayment": 0,//未付款
     *              "accomplish": 0,//已完成
     *              "cancel": 1//已取消
     *          }
     *      }
     *  }
     */
    public function mySubscribeCount(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->subscribe->putimeCount($user->item_id);

        return $this->successResponse('success',['data' =>$data]);
    }

    /**
     * @api {post} /student/payment 学时付款(student payment)
     * @apiDescription 学时付款(student payment)
     * @apiGroup Student
     * @apiSampleRequest /api/student/payment
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [putime_id]  待支付学时id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": []
     *   }
     */
    public function payment(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $putime_id = $request->input('putime_id');

        if(!$putime_id){
            return $this->errorResponse('参数错误');
        }

        $data = $this->subscribe->paymentDetail($user->item_id, $putime_id);

        if($data){
            $transformer = new PaymentDetailTransformer;

            $data = $transformer->transform($data);

        }

        return $this->successResponse('success',['data'=>$data]);
    }

    /**
     * @api {post} /student/cancelPeriod  取消预约(student cancelPeriod)
     * @apiDescription  取消预约(student cancelPeriod)
     * @apiGroup Student
     * @apiSampleRequest /api/student/cancelPeriod
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [pid]  学时id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "取消成功",
     *       "status_code": 200
     *   }
     */
    public function cancelPeriod(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'putime_id'=>$request->get('pid'),
            'student_id'=>$user->item_id
        ];
        if(!$param['putime_id']){
            return $this->errorResponse('参数错误');
        }
        $status_info = $this->subscribe->deleAllPutime($param['putime_id'],$param['student_id']);
        if($status_info !== false){

            if($status_info->km == 2){
                $km = '科二实操练习';
            }else{
                $km = '科三实操练习';
            }
            $msg['content'] = '你取消了'.$status_info->coach->name.'教练：'.date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime).' 的'.$km;
            $msg['from_type'] = 3;//消息来源学员
            $msg['from_id'] = $user->item->id;
            $msg['to_type'] = 1;//消息接受学员
            $msg['to_id'] = $user->item->id;

            if($user->item->device_type == 'ios'){
                $msg['device_type'] = 1;
            }elseif($user->item->device_type == 'android'){
                $msg['device_type'] = 2;
            }

            $this->message->store($msg);


            if( $user->item->device_token ) {
                $umen = new Umeng($user->item->device_type, 3);
                $umen->sendNotificationToDevices(['title' => '预约取消提示', 'text' => $msg['content'], 'device_tokens' => $user->item->device_token]);
            }
            $msg['content'] = $user->item->name.'学员取消了您：'.date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime).' 的'.$km;
            $msg['from_type'] = 1;//消息来源
            $msg['from_id'] = $user->item->school_id;
            $msg['to_type'] = 2;//消息接受教练
            $msg['to_id'] = $status_info->coach->id;
            $msg['device_type'] = 3;
            $this->message->store($msg);
            $coach_id = User::where('item_id',$status_info->coach->id)->where('item_type','App\Models\Coach')->value('id');
            $student_count = StudentCount::where('student_id',$user->item_id)->first();
            $data['km'] = $status_info->km;
            $data['status'] = 2;
            $data['userId'] = $user->id;
            $data['name']  = $user->item->name;
            $data['phone'] = $user->item->phone;
            $data['cocahUserId'] = $coach_id;
            $data['cocahName'] = $status_info->coach->name;
            $data['cocahPhone'] = $status_info->coach->mobile;
            $data['location'] = '';
            $data['return_hours'] = $status_info->study_time;
            $data['surplus_hours'] = $student_count->km2period + $student_count->km3period;
            $data['times'] = date('Y-m-d H:i', $status_info->startime).' ~ '.date('H:i', $status_info->endtime);
            $data['userType'] = 1;
            $this->subscribe->post_weixin_student_yy($data);
            return $this->successResponse('取消成功');
        }else{
            return $this->errorResponse($this->subscribe->error?$this->subscribe->error:'操作失败');
        }
    }

    /**
     * @api {get} /student/periodStatistics 学时统计(student periodStatistics)
     * @apiDescription 学时统(student periodStatistics)
     * @apiGroup Student
     * @apiSampleRequest /api/student/periodStatistics
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "count": [
     *          "notStudy": 1, //未完成
     *          "notPayment": 0,//未付款
     *          "accomplish": 0,//已完成
     *          "cancel": 1//已取消
     *      ]
     *   }
     */
    public function periodStatistics(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $list = $this->subscribe->putimeCount($user->item_id);

        return $this->successResponse('success',['count'=>$list]);
    }

    /**
     * @api {get} /student/feedback 教练反馈(student feedback)
     * @apiDescription 教练反馈(student feedback)
     * @apiGroup Student
     * @apiSampleRequest /api/student/feedback
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [putime_id]  取消学时id
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *  {
     *      "message": "操作成功",
     *      "status_code": 200,
     *      "data": {
     *          "id": 158, //学时id
     *          "school_id": 36,//驾校id、
     *          "coach_id": 507,//教练id、
     *          "coachname": "肖均2",//教练姓名
     *          "coachphoto": "http://img.exc360.com/photo/2016/10/23/1477189571_PS0.jpg",//教练头像
     *          "mobile": "13512345678",//教练电话
     *          "km": 2,//科目
     *          "startime": 1496394000,//学时开始时间
     *          "endtime": 1496397600,//学时结束时间
     *          "money": 1,//金额
     *          "paymode": 2,//学时类型  1：先学后付 2：先付后学
     *          "quxiaotimes": "2017-06-02 15:22:15", //学时取消时间
     *          "feedback": "154546", //教练反馈内容
     *          "feedbacktime": "2017-06-02 15:22:15", //时间
     *      }
     *  }
     */
    public function feedback(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'putime_id'=>$request->get('putime_id'),
            'student_id'=>$user->item_id
        ];

        $list = $this->subscribe->getFeedback($param);
        return $this->responseItem($list,new FeedbackTransformer());
    }



    /**
     * @api {get} /student/myMessages 我的消息(student messages)
     * @apiDescription 我的消息(student messages)
     * @apiGroup Student
     * @apiSampleRequest /api/student/myMessages
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [page]  1
     * @apiParam {Number} [size]  10
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": []
     *   }
     */
    public function myMessages(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $size = $request->get('size', 10);
        $param['to_id'] = $user->item_id;
        $param['to_type'] = 1;//发送给学员的消息
        $param['page'] = $request->get('page', 1);

        $lists = $this->message->index($param,'',$size);

        $data = [];
        $data['list'] = [];
        if(count($lists)){

            $transformer = new MessageTransformer;

            foreach($lists['list'] as $v){
                if($v->from_type == 1){
                    $from_user =  School::find($v->from_id);
                }else{
                    $from_user =  Coach::find($v->from_id);
                }

                $v->fromuser = $from_user;

                $data['list'][] = $transformer->transform($v);
            }
        }
        $data['count'] = $lists['count'];

        return $this->successResponse('success',['data' => $data]);
    }






    /**
     * @api {get} /student/myCenter 我的个人中心(student messages)
     * @apiDescription 我的个人中心(student messages)
     * @apiGroup Student
     * @apiSampleRequest /api/student/myCenter
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *       "message": "",
     *       "status_code": 200,
     *       "data": []
     *   }
     */
    public  function myCenter()
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->student->mycenter($user->item);

        return $this->successResponse('success',['data'=>$data]);
    }



    /**
     * @api {get} /student/studyTimeLog 我的学时钱包
     * @apiDescription 我的学时钱包(student messages)
     * @apiGroup Student
     * @apiSampleRequest /api/student/studyTimeLog
     * @apiPermission none
     * @apiParam {Number} [page]  page
     * @apiParam {Number} [size]  size
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
            "code": 200,
            "data": {
                "total": 40,
                "list": [
                    {
                        "id": 25,
                        "type": 1//操作类型 1：学时预约  2：取消预约',
                        "school_id": 36,
                        "coach_id": 498,
                        "putime_id": 221,
                        "put_startime": "2017-07-08 16:00:00",//培训开始时间
                        "put_endtime": "2017-12-06 12:28:27",//培训结束时间
                        "money": 1,
                        "student_id": 4899,
                        "operation_id": 4899,
                        "operationtime": "2017-07-07 11:09:01",
                        "created_at": "2017-07-07 11:09:01",//扣除时间
                        "updated_at": "2017-07-07 11:09:01",
                        "study_times": 1,//学时，type=1为减，type=2为加
                        "coachname": "李泉"//教练
                     },
     *          ]
     *   }
     */
    public function studyTimeLog(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param = [
            'student_id' => $user->item_id,
            'page' => $request->input('page', 1),
            'size' => $request->input('size', 15),
        ];

        $data = $this->student_count->index($param);

        return $this->successResponse('s uccess', ['data' => $data]);
    }


    /**
     * @api {get} /student/complaints 我的投诉
     * @apiDescription 我的投诉
     * @apiGroup Student
     * @apiSampleRequest /api/student/complaints
     * @apiPermission none
     * @apiParam {Number} [page]  page
     * @apiParam {Number} [size]  size
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {
    "total": 40,
    "list": [
    {
    "id": 25,
    "type": 1//操作类型 1：学时预约  2：取消预约',
    "school_id": 36,
    "coach_id": 498,
    "putime_id": 221,
    "put_startime": "2017-07-08 16:00:00",//培训开始时间
    "put_endtime": "2017-12-06 12:28:27",//培训结束时间
    "money": 1,
    "student_id": 4899,
    "operation_id": 4899,
    "operationtime": "2017-07-07 11:09:01",
    "created_at": "2017-07-07 11:09:01",//扣除时间
    "updated_at": "2017-07-07 11:09:01",
    "study_times": 1,//学时，type=1为减，type=2为加
    "coachname": "李泉"//教练
    },
     *          ]
     *   }
     */
    public function complaints(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $size = $request->get('size',10);

        $param = [
            'page'=>$request->get('page', 1)
        ];

        $data = $this->student_state->index($param,$user->item,$size);

        return $this->successResponse('success', ['data' => $data]);
    }


    /**
     * @api {get} /student/myschool 我的驾校
     * @apiDescription 我的驾校
     * @apiGroup Student
     * @apiSampleRequest /api/student/myschool
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
            "code": 200,
            "data": {}
     *   }
     */
    public function mySchool(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->student->mySchool($user->item);

        return $this->successResponse('success', ['data' => $data]);
    }


    /**
     * @api {get} /student/myschoolevaluates 我的驾校评价列表
     * @apiDescription 我的驾校我的驾校评价列表
     * @apiGroup Student
     * @apiSampleRequest /api/student/myschoolevaluates
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [page]  page
     * @apiParam {Number} [size]  size
     * @apiParam {Number} [type]  type 1非常满意 2满意 3一般 为空表示所有
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function mySchoolEvaluates(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $page = $request->input('page');
        $size = $request->input('size');
        $type = $request->input('type');
        $is_my = $request->input('viewMy', 0);

        $data = $this->evaluation->schoolEvaluates($user->item, $type, $page, $size, $is_my);

        return $this->successResponse('success', ['data' => $data]);
    }



    /**
     * @api {get} /student/mycoachs 我的教练
     * @apiDescription 我的教练
     * @apiGroup Student
     * @apiSampleRequest /api/student/mycoachs
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function myCoachs(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->student->myCoachs($user->item);

        return $this->successResponse('success', ['data' => $data]);
    }


    /**
     * @api {get} /student/mycoachevaluates 我的教练评价列表
     * @apiDescription 我的教练评价列表
     * @apiGroup Student
     * @apiSampleRequest /api/student/mycoachevaluates
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {Number} [page]  page
     * @apiParam {Number} [size]  size
     * @apiParam {Number} [type]  type 1非常满意 2满意 3一般 为空表示所有
     * @apiParam {Number} [coach_id]  coach_id 教练ID
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function myCoachEvaluates(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $page = $request->input('page');
        $size = $request->input('size');
        $type = $request->input('type');
        $coach_id = $request->input('coach_id', '');


        $coach_idar = [];
        if($coach_id){
            $coach_idar = [$coach_id];
        }else{
            $coach_idar = StudentCoach::select('cid')->where('stuid', $user->item_id)->get()->toArray();
        }



        $data = $this->comments->coachComments($coach_idar, $user->item, $type, $page, $size);

        return $this->successResponse('success', ['data' => $data]);
    }


    /**
     * @api {get} /student/showSchoolEvaluate 评价我的驾校
     * @apiDescription 评价我的驾校
     * @apiGroup Student
     * @apiSampleRequest /api/student/showSchoolEvaluate
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function showSchoolEvaluate()
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $school_info = $user->item->school;

        $data['userid'] = $school_info->id;
        $data['username'] = $school_info->phone;
        $data['nickname'] = $school_info->shortname;

        return $this->successResponse('success', ['data' => $data]);
    }


    /**
     * @api {get} /student/postSchoolEvaluate 评价我的驾校提交数据
     * @apiDescription 评价我的驾校提交数据
     * @apiGroup Student
     * @apiSampleRequest /api/student/postSchoolEvaluate
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiParam {String} [content]  content
     * @apiParam {Number} [status]  status
     * @apiParam {Number} [anonymity]  anonymity
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function postSchoolEvaluate(Request $request)
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $param['content']  = $request->input('content');//评论内容
        $param['status'] = $request->input('status');//满意度
        $param['anonymity'] = $request->input('anonymity');//是否匿名

        $this->evaluation->evaluateSchool($user->item, $param);

        return $this->successResponse('操作成功');
    }



    /**
     * @api {get} /student/getPayRecord 我的支付记录
     * @apiDescription 我的支付记录
     * @apiGroup Student
     * @apiSampleRequest /api/student/getPayRecord
     * @apiPermission none
     * @apiHeader {String} Authorization 用户旧的jwt-token, value 以 Bearer 开头
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *      "message": "success",
    "code": 200,
    "data": {}
     *   }
     */
    public function getPayRecord()
    {
        $user = JWTAuth::parseToken()->authenticate();//验证token

        if(!$this->checkToken($user->item, JWTAuth::getToken())){
            return $this->errorResponse('你的账号在其他地方登录', 401);
        }

        $data = $this->order_list->index($user->item);

        return $this->successResponse('success', ['data' => $data]);
    }

}